<?php
/**
 *  礼物背包
 * ds
 * 2020.08.13
 */
namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;

class GiftBackpack extends Model{

    protected $table = 'ln_gift_backpack';     //数据库内完整表名

    protected $primaryKey = 'id';    //主键名

    protected $fillable = [
        'id',      // 主键id
        'user_id',         //  用户id
        'gift_id',         //  礼物id
        'number',         //  数量
        'state',         //  1正常2冻结
    ];

    public $timestamps = false;

    public function sendBackpackGift($user_id, $gift_id, $number = 1) {
        $data['user_id'] = $user_id;
        $data['gift_id'] = $gift_id;
        if ($this->where($data)->first()) {
            $this->where($data)->increment('number', $number);
        } else {
            $data['number'] = $number;
            $this->insert($data);
        }
    }
}
